import React from 'react';
const GuestEdit = () => {
    const [form] = React.UI.Form.useForm()
    const [searchParams] = React.Router.useSearchParams();
    const gid = searchParams.get('gid') ? searchParams.get('gid') : 0;

    React.useEffect(() => {
        GuestInfoData();
    }, [gid])

    const GuestInfoData = async () => 
    {
        let result = await React.HTTP.post('/guest/info', {
            gid: gid,
            busid: React.Business.id,
        })

        if(result.code == 1) 
        {
            form.setFieldsValue({
                nickname: result.data.nickname,
                mobile: result.data.mobile,
                gender: result.data.gender,
            })
        }
    }

    //表单事件
    const OnSubmitAddEvent = async (values: any) => 
    {
        values.busid = React.Business.id
        values.gid = gid
        let result = await React.HTTP.post('/guest/edit', values)
        if (result.code == 1) 
        {
            React.success(result.msg, () => React.navigate(-1))
        }
        else 
        {
            React.error(result.msg)
        }
    }
    return (
        <>
            <React.UI.Form
                form={form}
                layout='horizontal'
                onFinish={OnSubmitAddEvent}
                footer={
                    <React.UI.Button block type='submit' color='primary' size='large'>
                        提交
                    </React.UI.Button>
                }
            >
                {/* 昵称 */}
                <React.UI.Form.Item name='nickname' label='昵称' rules={[{ required: true, message: '昵称不能为空' }]}>
                    <React.UI.Input placeholder='请输入昵称'/>
                </React.UI.Form.Item>

                {/* 手机号码 */}
                <React.UI.Form.Item name='mobile' label='手机号码' rules={[{ required: true, message: '请填写手机号码' }, { pattern: /^1[3456789]\d{9}$/, message: '手机号格式不对' }]}>
                    <React.UI.Input placeholder='请输入手机号码' />
                </React.UI.Form.Item>

                {/* 性别 */}
                <React.UI.Form.Item name='gender' label='性别' rules={[{ required: true, message: '性别不能为空' }]}>
                    <React.UI.Radio.Group>
                        <React.UI.Space direction='horizontal'>
                            <React.UI.Radio value='0'>女</React.UI.Radio>
                            <React.UI.Radio value='1'>男</React.UI.Radio>
                        </React.UI.Space>
                    </React.UI.Radio.Group>
                </React.UI.Form.Item>
            </React.UI.Form>
        </>
    )
}
export default GuestEdit;